package hku.cs.lunuo.voter.impl;

import hku.cs.lunuo.rank.DefaultLabel;
import hku.cs.lunuo.rank.model.Label;
import hku.cs.lunuo.voter.VotedGlobal;
import hku.cs.lunuo.voter.VotedUnit;
import hku.cs.lunuo.voter.Voter;

public class OMinos extends Voter {

	@Override
	public Label vote(VotedUnit u, VotedGlobal g) {
		int falseCases = u.tf.getFlsTimes();
		int trueCases = u.tf.getTruTimes();
		float susc, noise;

		susc = (float) (falseCases / Math.sqrt(g.totalTF.getFlsTimes()
				* (falseCases + trueCases)));
		
		if(g.totalTF.getFlsTimes()==falseCases)
			noise = 0;
		else
			noise = (float) (
					(g.totalTF.getFlsTimes()-falseCases) 
					/ 
					Math.sqrt(
						g.totalTF.getFlsTimes() * (g.totalTF.getFlsTimes()-falseCases + g.totalTF.getTruTimes()-trueCases)
					)
				);
		return new DefaultLabel(susc-noise);
	}

}
